package com.cz.yhc;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

public class QueryTicket {

    public static void main(String[] args) {
         
        boolean toDo = false;
        do{
            String bearer = "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImE5ODM4NWEzLTE0ZjAtNDBkOC1hYWUzLWI1OGY2MzU5NzQ5ZiJ9.6YGI2ohoErpXbsuh4pz-eKFQ9s0dI0AxcwJVhS-PjblgId0Z34FBUOl3PE25AdXRlHX1HHV5wLVKnZjP6uqV9w";
            String url = "https://yhcxcx.cnosr.com/api/MallTicketOrder/MallTicketOrder/getSeat?ticketId=56&date=2025-08-24&time=20:10";
            HttpResponse response = HttpRequest.get(url)
                    .header("Content-Type", "application/json") // 设置请求头
                    .header("authorization",
                            "Bearer "+bearer) // 设置自定义
                                                                                                                                                                                                                                                                                                                                                                                               // header
                    .header("Buthorization",
                            "Bearer "+bearer)// 设置请求体
                    .header("User-Agent",
                            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36")
                    .timeout(10000) // 设置超时时间，毫秒
                    .execute();
    
            if (response.isOk()) {
                String body = response.body();
                System.out.println("请求返回数据:" + body);
                JSONObject result = JSONUtil.parseObj(body);
                JSONArray resultArray = result.getJSONObject("data").getJSONArray("haveSell");
                if (!resultArray.isEmpty()) {
                    for (int i = 0; i < resultArray.size(); i++) {
                        JSONObject item = resultArray.getJSONObject(i);
                        String seatRow = item.getStr("row");
                        if (seatRow.equals("1")) {
                            System.out.println(seatRow + "排" + item.getStr("num") + "座"); 
                        }
    
                    }
                }
            } else {
                System.out.println("请求失败" + response.getStatus() + ":" + response.body()); 
                toDo = true;
            }
        }while(toDo);
        

    }
}
